import urllib.request
import time

def get_img(pic_id, url):
    res = urllib.request.urlopen(url)
    pic = res.read()
    with open(f'test/{pic_id}.jpg', 'wb') as f:
        f.write(pic)
    print(f'图片 {pic_id} 已经保存!')

def main():
    url = 'https://picsum.photos/id/{}/200/300'
    pic_ids = [i for i in range(20)] ;
    urls=[(url.format(n)) for n in range(20)]
    start = time.time()
    for _ in map(get_img, pic_ids, urls):
        pass
    end = time.time()
    msg = '共耗时{:.3f}秒下载完成。'
    print(msg.format(end-start))
if __name__ == '__main__':
    main()
